package com.siwei.mes.entity.system;

import cn.dev33.satoken.stp.StpUtil;
import com.alibaba.fastjson.JSONObject;
import com.siwei.mes.common.validator.AddGroup;
import com.siwei.mes.common.validator.UpdateGroup;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.experimental.Accessors;

import javax.persistence.Column;
import javax.persistence.Id;
import javax.persistence.Table;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
import java.io.Serializable;
import java.util.Date;


/**
 * 用户证书(UserCertificate)实体类
 *
 * @author linzi
 * @since 2024-07-16 14:38:50
 */
@Data
@Accessors(chain = true)
@Table(name = "pk_user_certificate")
@ApiModel(value = "UserCertificate", description = "用户证书")
public class UserCertificate implements Serializable {
    private static final long serialVersionUID = -68457589344175478L;
    /**
     * 主键id
     */
    @Id
    @ApiModelProperty(value = "用户证书主键ID", name = "id")
    @NotNull(groups = {UpdateGroup.class}, message = "用户证书主键id为空")
    private Long id;
    /**
     * 用户id
     */
    @Column(name = "user_id")
    @ApiModelProperty(value = "用户id", name = "userId")
    @NotNull(groups = {AddGroup.class, UpdateGroup.class}, message = "用户id为空")
    private Long userId;
    /**
     * 证书编号
     */
    @Column(name = "certificate_no")
    @ApiModelProperty(value = "证书编号", name = "certificateNo")
    @NotBlank(groups = {AddGroup.class, UpdateGroup.class}, message = "证书编号为空")
    private String certificateNo;
    /**
     * 证书名称
     */
    @Column(name = "certificate_name")
    @ApiModelProperty(value = "证书名称", name = "certificateName")
    @NotBlank(groups = {AddGroup.class, UpdateGroup.class}, message = "证书名称为空")
    private String certificateName;
    /**
     * 发放单位
     */
    @Column(name = "certificate_company")
    @ApiModelProperty(value = "发放单位", name = "certificateCompany")
    private String certificateCompany;
    /**
     * 证书图片  多个用逗号隔开
     */
    @Column(name = "certificate_img")
    @ApiModelProperty(value = "证书图片  多个用逗号隔开", name = "certificateImg")
    private String certificateImg;

    /**
     * 以下  配比、砼操、水泥、骨料、砂浆、管理、设备、网管、外掺、化学、钢筋、构件 都是一个json
     * {"startTime":"发证日期","endTime":"有效期"}
     */
    @Column(name = "peibi")
    @ApiModelProperty(value = "配比")
    private JSONObject peibi;

    @Column(name = "tongcao")
    @ApiModelProperty(value = "'砼操'")
    private JSONObject tongcao;

    @Column(name = "shuini")
    @ApiModelProperty(value = "水泥")
    private JSONObject shuini;

    @Column(name = "guliao")
    @ApiModelProperty(value = "骨料")
    private JSONObject guliao;

    @Column(name = "shajiang")
    @ApiModelProperty(value = "砂浆")
    private JSONObject shajiang;

    @Column(name = "guanli")
    @ApiModelProperty(value = "管理")
    private JSONObject guanli;

    @Column(name = "shebei")
    @ApiModelProperty(value = "设备")
    private JSONObject shebei;

    @Column(name = "wangguan")
    @ApiModelProperty(value = "网管")
    private JSONObject wangguan;

    @Column(name = "waican")
    @ApiModelProperty(value = "外掺")
    private JSONObject waican;

    @Column(name = "huaxue")
    @ApiModelProperty(value = "化学")
    private JSONObject huaxue;

    @Column(name = "gangjin")
    @ApiModelProperty(value = "钢筋")
    private JSONObject gangjin;

    @Column(name = "goujian")
    @ApiModelProperty(value = "构件")
    private JSONObject goujian;

    /**
     * 创建人
     */
    @Column(name = "creater")
    @ApiModelProperty(value = "创建人", name = "creater")
    private Long creater;
    /**
     * 创建时间
     */
    @Column(name = "create_time")
    @ApiModelProperty(value = "创建时间", name = "createTime")
    private Date createTime;
    /**
     * 修改人
     */
    @Column(name = "updater")
    @ApiModelProperty(value = "修改人", name = "updater")
    private Long updater;
    /**
     * 更新时间
     */
    @Column(name = "update_time")
    @ApiModelProperty(value = "更新时间", name = "updateTime")
    private Date updateTime;
    /**
     * 是否删除  1-删除
     */
    @Column(name = "is_del")
    @ApiModelProperty(value = "是否删除  1-删除", name = "isDel")
    private Integer isDel;

    public UserCertificate init(boolean isCreate) {
        this.setUpdater(StpUtil.isLogin() ? StpUtil.getLoginIdAsLong() : null)
                .setUpdateTime(new Date());
        if (isCreate) {
            this.setCreater(StpUtil.isLogin() ? StpUtil.getLoginIdAsLong() : null)
                    .setCreateTime(new Date()).setIsDel(0);
        }
        return this;
    }
}
